#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QTimer * timer1 = new QTimer(this);
    connect(ui->pushButton,&QPushButton::clicked,[=](){
        //刷新画布达到移动的效果,用update更新
            timer1->start(200);
    });
    connect(timer1,&QTimer::timeout,[=](){
        posX+= 20 ;
        update();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *)
{
    //创建画家
    QPainter painter(this);
    //    painter.drawEllipse(QPoint(100,100),50,50);
    //    //设置抗锯齿 效率不高S
    //    painter.setRenderHint(QPainter::Antialiasing);
    //    painter.drawEllipse(QPoint(100,200),50,50);
    //    //画矩形
    //       painter.drawRect(QRect(10,10,50,50));
    //       //移动画家
    //       painter.translate(QPoint(100,100));//相当于起点
    //       painter.drawRect(QRect(150,10,50,50));
    //       painter.save();//保存画布状态
    //       painter.restore();//还原画布

    //    //创建画笔
    //    QPen pen(QColor(255,200,100));
    //    //画笔宽度
    //    pen.setWidth(5);
    //    //画笔风格
    //    pen.setStyle(Qt::PenStyle::DotLine);
    //    //使用画笔
    //    painter.setPen(pen);
    //    //QWidget继承了Object和QPaintDevice
    //    //画刷填充颜色
    //    QBrush brush(Qt::green);
    //    pnter.setBrush(brush);
    //    //利用画家画画
    //    painter.drawLine(QPoint(0,0),QPoint(100,100));
    //    //画个圆
    //    painter.drawEllipse(QPoint(100,100),100,100);
    //    //画矩形
    //    painter.drawRect(QRect(10,10,50,50));
    //    //画字体
    //    painter.drawText(QRect(50,100,100,50),"你好");
    //利用画笔加载资源文件

    ////////////////////////////////////////
    painter.drawPixmap(posX,100,QPixmap(":/Image/LuffyQ.png"));
    //超出屏幕重置位置
    if(posX > this->width()){
        posX = 0;
    }

}




void MainWindow::on_pushButton_clicked()
{

}
